home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 3200 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  1.6 KB

  1. Path: atglab.bls.com!Alun.Champion
  2. From: Alun.Champion@bridge.bst.bls.com (Alun Champion)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Best way to "define" flag values?
  5. Date: 22 Jan 1996 20:43:01 GMT
  6. Organization: Computer People Inc.
  7. Distribution: na
  8. Message-ID: <ALUN.CHAMPION.96Jan22154301@g7240065.bridge.bst.bls.com>
  9. References: <marnoldDLIv9w.1s4@netcom.com> <cmanDLKAqG.Drt@netcom.com>
  10. NNTP-Posting-Host: bstfirewall.bst.bls.com
  11. In-reply-to: cman@netcom.com's message of Mon, 22 Jan 1996 02:54:16 GMT
  12.  
  13. In article <cmanDLKAqG.Drt@netcom.com> cman@netcom.com (Mike Austin) writes:
  14.  
  15. : Here's a little essay that I did a while ago.  I still think the same 
  16. : way now, but my views have broadened...
  17.  
  18. : [snip]
  19. :
  20. : class Window {
  21. :  public:
  22. :       Window(Style aStyle);
  23. :       enumbit Style { NoTitle, NoBorder, NoResize };
  24. : };
  25.  
  26. : create a window with all three window styles set:
  27.  
  28. :       win(Window::NoTitle | Window::NoBorder | Window::NoResize);
  29. :
  30. : [snip]
  31.  
  32. There is a problem with this - namely enum's do not have an operator | ()
  33. defined on them, so it converts them to an intergral type to perform these
  34. operations (on my machine the integral type is int).
  35. So I get this error:
  36.  
  37. Error:  error: bad argument  1 type for Window::Window(): int (Window::Style expected)
  38.  
  39. With the namespace declaration, your dislike for qualified enums are removed.
  40.  
  41.     using Window::Style;
  42.     ...
  43.     win(NoTitle | NoBorder | NoResize);
  44.  
  45. This has the advantage of not polluting the global namespace still retains
  46. type semantics (#defines don't) and can be used without having to
  47. qualify the enumerated values ;')
  48.  
  49. Regards
  50.  
  51.    -A.
  52.  
  53. -- 
  54. | A.Champion                |
  55.